﻿#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Callbacks;
/// <summary>
/// SceneView抽象
/// </summary>
//[EditorWindowTitle(title ="", useTypeNameAsIconName = false, icon = "UnityEditor.SceneView")]
public abstract class AbsESF_SceneView : SceneView
{
    /// <summary>
    /// singleLineHeight
    /// </summary>
    public float singleLineHeight { get { return EditorGUIUtility.singleLineHeight; } }
    /// <summary>
    /// viewWidth
    /// </summary>
    public float viewWidth { get { return EditorGUIUtility.currentViewWidth; } }

    /// <summary>
    /// OnEnable
    /// </summary>
    public override void OnEnable()
    {
        base.OnEnable();
        EditorApplication.wantsToQuit += EditorApplication_wantsToQuit;
    }
    
    private bool EditorApplication_wantsToQuit()
    {
        Close();
        return true;
    }

    /// <summary>
    /// EditorApplication wantsToQuit
    /// </summary>
    protected virtual void OnWantsToQuit() { }

    /// <summary>
    /// OnDisable
    /// </summary>
    public override void OnDisable()
    {
        base.OnDisable();
        EditorApplication.wantsToQuit -= EditorApplication_wantsToQuit;
    }

    #region DidReloadScripts
    [DidReloadScripts]
    static void OnSceneViewEditorAbsESF_SceneView_DidReloadScripts()
    {
        if (sceneViews != null)
        {
            foreach (var key in sceneViews)
            {
                if (key is AbsESF_SceneView)
                {
                    (key as AbsESF_SceneView).OnDidReloadScripts();
                }
            }
        }
    }

    /// <summary>
    /// 脚本编译完成
    /// </summary>
    protected virtual void OnDidReloadScripts() { }
    #endregion
}
#endif
